<?php
pcntl_signal(SIGINT,function ($signo){
    fprintf(STDOUT,"pid %d 接收到 %d信号\n",posix_getpid(),$signo);
});
pcntl_signal(SIGALRM,function ($signo){
    fprintf(STDOUT,"pid %d 接收到%d\n",posix_getpid(),$signo);
});

$mapPid = array();
$pid = pcntl_fork();
if ($pid>0){
    $mapPid[]  = $pid;
    $pid = pcntl_fork();
    if ($pid>0){
        while (1){
            pcntl_signal_dispatch();
            sleep(2);
        }
        exit(0);
    }
}
while (1){
    pcntl_signal_dispatch();
    fprintf(STDOUT,"pid =%d, ppid=%d,pgid=%d doing...\n",
        posix_getpid(),posix_getppid(),posix_getpgrp());
    sleep(2);
}